﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace xiangmu1
{
    public partial class H_Y_CZ : Form
    {
        public H_Y_CZ()
        {
            InitializeComponent();
        }
        public string kahao;

        public double jine;//穿过来的会员金额
        public int id;
        private void H_Y_CZ_Load(object sender, EventArgs e)
        {
            lblkahao.Text = kahao;
            string sql2 = "select * from  PayClass";
            DataTable dt2 = FrmHotel.DBHelper.SelectForTable(sql2);
            DataRow dr2 = dt2.NewRow();
            dr2["PayId"] = 0;
            dr2["PayName"] = "请选择";
            dt2.Rows.InsertAt(dr2, 0);
            this.comboBox1.DisplayMember = "PayName";
            this.comboBox1.ValueMember = "PayId";
            this.comboBox1.DataSource = dt2;
        }
        public void chongzhi()
        {
            int hao=Convert.ToInt32( this.lblkahao.Text);
            int moneyq=Convert.ToInt32(this.txt_money.Text);
            int fangshi=Convert.ToInt32(comboBox1.SelectedValue);
            DateTime date=DateTime.Now;
            string name="Admin";
            if (moneyq==0)
            {
                MessageBox.Show("请输入充值金额！");
                return;
            }
            if (fangshi==0)
            {
                MessageBox.Show("请选择充值方式！");
                return; 
            }
            string sqq = string.Format("select VpMoney from VipInfo where VpKaHao='{0}'", kahao);
            float money =Convert.ToSingle(FrmHotel.DBHelper.SelectOne(sqq));

            string sql = string.Format("update VipInfo set VpMoney={0} where VpKaHao='{1}' ", float.Parse(txt_money.Text) + money, lblkahao.Text);
            int hang = FrmHotel.DBHelper.ExecuteUpdate(sql);
            if (hang > 0)
            {
                this.DialogResult = DialogResult.OK;
                chongzhijilu();
                this.Close();
                string sql1 = string.Format("insert  into  CongZInfo values({0}, {1},{2},'{3}','{4}')", id, moneyq, fangshi, date, name);
                int hang1= FrmHotel.DBHelper.ExecuteUpdate(sql1);
                if (hang1 > 0)
                {
                    MessageBox.Show("充值成功");   
                    this.DialogResult = DialogResult.OK;
                    chongzhijilu();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("充值失败");
                }
            }
           
            else
            {
                MessageBox.Show("账号或密码错误，充值失败");
            }

        }
        public void chongzhijilu()
        {
          

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string m = txt_money.Text;
            if (string.IsNullOrEmpty(m))
            {
                MessageBox.Show("请输入金额！");
                return;
            }
            chongzhi();
        }

        private void txt_money_TextChanged(object sender, EventArgs e)
        {
           
        }

        
    }
}
